//
//  GiftViewModel.swift
//  七哥直播
//
//  Created by seven on 2017/12/26.
//  Copyright © 2017年 seven. All rights reserved.
//

import Foundation

class GiftViewModel{
    lazy var giftlistData: [GiftPackage] = [GiftPackage]()
}
extension GiftViewModel{
    func loadGiftData(complete: @escaping () -> ()){
        if giftlistData.count != 0 {complete()}
        NetworkTools.requestData(.get, URLString: "http://qf.56.com/pay/v4/giftList.ios", parameters: ["type" : 0, "page" : 1, "rows" : 150]) { (data) in
            let dataDict = data["message"].dictionaryObject!
            for i in 0 ..< dataDict.count {
                guard let dict = dataDict["type\(i+1)"] as? [String : Any] else { continue }
                self.giftlistData.append(GiftPackage(dict: dict))
            }
            self.giftlistData = self.giftlistData.filter({return $0.t != 0}).sorted(by: {return $0.t > $1.t})
        }
    }
}
